import request from '@/utils/request'
/**
 * 分页订单列表
 * @param pageNum
 * @param pageSize
 */
const getList = function(pageNum, pageSize, params) {
  return request({
    url: '/sysOrder/list?pageNum='+pageNum+"&pageSize="+pageSize,
    // url: '/sysOrder/list',
    method: 'post',
    data: params != null ? params : {}
  })
}

/**
 * 更新订单
 * @param data
 */
const update = function(data) {
  return request({
    url: '/sysOrder/update',
    method: 'post',
    data: data
  })
}

/**
 * 订单资料审核
 * @param data
 */
const orderDataAuth = function(data) {
  return request({
    url: '/sysOrder/orderDataAuth',
    method: 'post',
    data: data
  })
}

/**
 * 更新备注
 * @param data
 */
const updateNotes = function(data) {
  return request({
    url: '/sysOrder/updateNotes',
    method: 'post',
    data: data
  })
}

/**
 * 下载保险Excel
 * @param url
 * @param data
 */
const orderExcelDownload = function(url,data) {
  window.location.href = url + '/sysOrder/orderExcelDownload?startTime='+data.startTime+'&endTime='+data.endTime
}

/**
 * 生成合同
 * @param data
 */
const getContract = function(orderNo) {
  return request({
    url: '/sysOrder/getContract/' + orderNo,
    method: 'get',
    // responseType: 'blob',
    // headers: {
    //  contentType: 'application/json',
    //  cacheControl: 'no-cache'
    // },
    data: {}
  })
}
/**
 * 条件分页检索列表
 * @param data
 */
const search = function(data) {
  return request({
    url: '/sysOrder/search?pageNum='+data.pageNum+"&pageSize="+data.pageSize+"&mobile="+data.mobile+"&date="+data.date+"&oddNumber="+data.oddNumber,
    method: 'get'
  })
}

/**
 * 条件分页检索列表
 * @param data
 */
const getStock = function(data) {
  return request({
    url: '/sysStock/getCustomerInfo?mobile='+data.mobile,
    method: 'get'
  })
}

/**
 * 下载保险Excel
 * @param url
 * @param data
 */
const ANLCardDownload = function(url,id) {
  window.location.href = url + '/sysOrder/ANLCardDownload?orderId='+id
}
/**
 * 批量下载
 * @param url
 * @param data
 */
const batchDownload = function(url,type,ids) {
  window.location.href = url + '/sysOrder/batchDownload?type='+type+'&ids='+ids;
}
//获取可用套餐
const getAllSetMeal = function (data) {
  sessionStorage.setItem("agentCode",data.agentCode)
  return request({
    url: '/setMeal/getSetMeal2?miles='+data.miles+'&registerDate='+new Date(data.registerDate).getTime()+'&isUsedcar='+data.isUsedcar+'&mealType='+data.mealType+'&carModelId='+data.carModelId,
    method: 'get'
  })
}
//获取套餐价格
const getPrice = function (data) {
  return request({
    url: '/tariff/getPrice2?miles='+data.miles+'&registerDate='+data.registerDate+'&isUsedcar='+data.isUsedcar+'&setMealId='+data.mealId+'&carModelId='+data.carModelId,
    method: 'get'
  })
}
//获取优惠价格
const getCouponPrice = function (data) {
  return request({
    url: '/coupon/getPrice?couponCode='+data.coupon+'&premium='+data.premium+'&extendYear='+data.mealId,
    method: 'get'
  })
}
//订单退款
const orderReturn = function (data) {
  return request({
    url: '/sysOrder/orderReturn',
    method: 'post',
    data: data
  })
}
// 新下订单通知
const notifyMsg = function () {
  return request({
    url: '/sysOrder/notifyMsg',
    method: 'post',
    // data: data
  })
}//已读订单
const read = function (data) {
  return request({
    url: '/sysOrder/read',
    method: 'post',
    data: data
  })
}
//取消订单
const cancelOrder = function (data) {
  return request({
    url: '/sysOrder/cancelOrder',
    method: 'post',
    data: {
      ids: data
    }
  })
}
export const orderApi = {
  getList: getList,
  update:update,
  orderDataAuth: orderDataAuth,
  updateNotes: updateNotes,
  search:search,
  getStock:getStock,
  getContract: getContract,
  orderExcelDownload: orderExcelDownload,
  ANLCardDownload: ANLCardDownload,
  batchDownload: batchDownload,
  getAllSetMeal:getAllSetMeal,
  getPrice:getPrice,
  getCouponPrice:getCouponPrice,
  orderReturn:orderReturn,
  read:read,
  cancelOrder:cancelOrder,
  notifyMsg:notifyMsg,
}
